<template>
	<view>
		<view class="shows">
			<view class="classify">
				<view @click="changeStatus(5)" :class="{'active':status == '5'}">全部</view>
				<view @click="changeStatus(1)" :class="{'active':status == '1'}">已发布</view>
				<view @click="changeStatus(0)" :class="{'active':status == '0'}">已下线</view>
			</view>
			<view>
				<view class="oneCard" v-for="(item,index) in itemList" :key="index">
					<view class="cardBox">
						<view class="cardName">
							{{item.introduce}}
						</view>
						<view class="cardStatus">
							<span v-if="item.status == '1'">已发布</span>
							<span class="off" v-else>已下线</span>
						</view>
					</view>

					<view class="cardOpt" v-if="item.status == '1'">
						<view class="revise same red" @click="againUp(item.id)">下线</view>
						<view style="color: #f1f1f1;">|</view>
						<view class="reuse same" @click="revise(item.id)">修改</view>
					</view>
					<view class="cardOpt" v-else>
						<view class="revise same" @click="revise(item.id)">修改</view>
						<view style="color: #f1f1f1;">|</view>
						<view class="reuse same" @click="againUp(item.id)">重新发布</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				status: 5,
				value: '',
				itemList: [],
				dataStatus: '',
				url: '',
				page:1,
			}
		},
		onLoad(options) {
			console.log('------------',options)
			
		},
		onShow() {
			var _this = this
			this.page = 1
			this.itemList = []
			this.getList()
		},
		onReachBottom(){
			console.log('上拉')
			if(this.page*10 >= this.scTotal){
				this.page = this.page + 1
				this.getList()
			}else{
				uni.showToast({
					title:'没有更多了'
				})
			}
		},
		methods: {
			// 选择状态 5为全部 1为已发布 0为已下线
			changeStatus(index){
				this.page = 1
				this.itemList = []
				this.status = index
				this.getList()
			},
			revise(id) {
				console.log(id)
				uni.navigateTo({
					url:'/pages/businessCard/businessCard?isEdit=1&id='+id
				})
			},
			getList(){
				let params = {
					page: this.page,
					num: 10,
				}
				if(this.status != 5) params.status = this.status
				uni.request({
					url: app.globalData.IP + 'addons/shopro/visiting_card/user_index',
					data: params,
					header: {
						token: app.globalData.token
					},
					method: 'GET',
					success: res => {
						console.log(res)
						if (res.data.code == 1) {
							this.total = res.data.data.total
							this.itemList = [...this.itemList,...res.data.data.data]
						}
					},
					fail: err => {
						
						console.log('发送数据失败')
					}
				})
			},
			// 重新发布
			againUp(id) {
				uni.request({
					url: app.globalData.IP + 'addons/shopro/visiting_card/changeStatus',
					data: {
						id: id
					},
					header: {
						token: app.globalData.token
					},
					method: 'POST',
					success: res => {
						console.log(res)
						if (res.data.code == 1) {
							uni.showToast({
								title: res.data.msg
							})
							this.itemList =[]
							this.getList()
						} else {
							uni.showToast({
								title: res.data.msg,
								icon:'none'
							})
						}
					},
					fail: err => {
						console.log('发送数据失败')
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background: #f7f7f7;
	}
	.classify {
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: #fff;
	}

	.classify view {
		padding: 20rpx 10rpx;
		font-size: 30rpx;
		font-weight: bold;
		border-bottom: 4rpx solid #fff;
	}

	.classify .active {
		color: #1e9efe;
		border-bottom: 4rpx solid #1e9efe;
	}

	.oneCard {
		margin: 20rpx;
		border-radius: 20rpx;
		background: #fff;
	}

	.cardBox {
		padding: 20rpx 0rpx;
		margin: 0rpx 20rpx;
		display: flex;
		justify-content: space-between;
		height: 140rpx;
		border-bottom: 1rpx solid #f1f1f1;
	}

	.cardName {
		width: 520rpx;
		font-size: 32rpx;
		word-wrap: break-word;
	}

	.cardStatus span {
		padding: 5rpx 10rpx;
		background-color: #1e9efe;
		color: #fff;
		border-radius: 10rpx;
	}

	.cardStatus .off {
		background-color: rgb(185, 185, 185);
	}

	.cardOpt {
		display: flex;
		justify-content: space-around;
		font-size: 30rpx;
		padding: 20rpx;
	}

	/* .cardOpt view {
		padding: 20rpx 0;
	} */
	.same {
		width: 200rpx;
		text-align: center;
		color: #1e9efe;
	}

	.rev {
		padding-bottom: 40rpx;
		background-color: #f1f1f1;
	}

	.topNav {
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 20rpx;
	}

	.backImg {
		width: 50rpx;
		height: 50rpx;
	}

	.backImg image {
		width: 100%;
		height: 100%;
	}

	.topSize {
		font-size: 30rpx;
		font-weight: bold;
		margin: 0 0 0 242rpx;
	}

	.tameInfo {
		margin: 30rpx;
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
	}

	.teams {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 25rpx 0;
	}

	.teams view {
		font-size: 30rpx;
		font-weight: bold;
	}

	.pointOut {
		font-size: 30rpx;
		font-weight: bold;
		padding: 0 0 0 30rpx;
	}

	input {
		text-align: right;
	}

	.upRev {
		width: 520rpx;
		padding: 10rpx 0;
		margin: 0 auto;
		font-size: 20rpx;
		color: #fff;
		background-color: #1e9efe;
		border-radius: 30rpx;
		text-align: center;
	}
	.red{
		color: red;
	}
</style>
